// Communication constants
var SERVER_TIMEOUT = 5000; // time in miliseconds

// Service urls
var SERVER_URL = "http://widgetcastor.appspot.com/";
var REGISTER = "register";
var LOGIN    = "login"   ;
var LOGOUT   = "logut"   ;
var SYNC     = "sync"    ;
var CHECKOUT = "checkout";

/**
*	Returns the entire url of the service passed in parameter.
*
*	@param service - String of the service required
*	@return String - url of the service requested
*/
function service(service){
	return SERVER_URL + service;
}


/**
*	Class: CastorServer
*
*	Work as an interface to handle the Castor web application.
*/
function Server(){
		

}

function test_server(){
	var serv = new Server();
	serv.sync("tcs5","castor","xml flag");
}

Server.prototype.sync = function(username, password, xml){
	$.ajax({
	
		type        : "POST",
		url         : service(SYNC),
		timeout     : SERVER_TIMEOUT,
		
		data        : 
		{
			'username' : username,
			'password' : password,
			'content'  : xml
		},
		
		success : function(msg)
		{
			//TODO check if the requisition was ok.
		},
		
		error : function()
		{
		
		}
					
	});			
};

Server.prototype.checkout = function(username, password){
	$.ajax({
				
		type    : "POST",
		url     : service(CHECKOUT),
		timeout : SERVER_TIMEOUT,
		
		data        : 
		{
			'username' : username,
			'password' : password
		},

		
		success : function(xml)
		{	
			user.projects = parseProjectXml(xml);
			user._project = 0;
			// user.setProjects(projects)			
		},
		
		error : function()
		{
		
		}
		
	});
};
